<script setup lang="ts">
import { ref, computed } from "vue";
import { ReloadOutlined } from "@ant-design/icons-vue";
const dataSource = ref([]);
import {
  GetAdutiView,
  GetEmployeeViewDetails,
  GetQueryPersonalWorkPlan,
  PostSubmitAssessmenteMoloyee,
  GetQueryPersonalScore,
  GetQueryRealTimeScore,
  PostoneClickReview,
} from "@/api/main";
import moment from "moment";
import { message } from "ant-design-vue";
import useUserStore from "@/stores/modules/user";
const userStore = useUserStore();
const columns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    align: "center",
    slots: { customRender: "index" },
  },
  {
    title: "审核人",
    dataIndex: "assessmentName",
    key: "assessmentName",
  },
  {
    title: "创建时间",
    dataIndex: "createdate",
    key: "createdate",
  },
  {
    title: "节点名称",
    dataIndex: "nodeName",
    key: "nodeName",
  },
  {
    title: "汇总类型",
    dataIndex: "summaryType",
    key: "summaryType",
    slots: { customRender: "summaryType" },
  },
  {
    title: "流程状态",
    dataIndex: "status",
    key: "status",
    slots: { customRender: "status" },
  },
  {
    title: "操作",
    dataIndex: "action",
    key: "action",
    align: "center",
    slots: { customRender: "action" },
  },
];
const drawerDataSource = ref([]);
const drawerColumns = [
  {
    title: "序号",
    dataIndex: "index",
    key: "index",
    align: "center",
    slots: { customRender: "index" },
  },
  {
    title: "姓名",
    dataIndex: "empname",
    key: "empname",
     align:"center"
  },
  {
    title: "职务",
    dataIndex: "duty",
    key: "duty",
     align:"center"
  },
  {
    title: "部门名称",
    dataIndex: "orgName",
    key: "orgName",
     align:"center"
  },
  {
    title: "个人评分",
    dataIndex: "selfScore",
    key: "selfScore",
     align:"center"
  },
  {
    title: "部门评分",
    dataIndex: "departmentScore",
    key: "departmentScore",
     align:"center"
  },
  {
    title: "支部评分",
    dataIndex: "secretaryScore",
    key: "secretaryScore",
     align:"center"
  },
  {
    title: "分管领导评分",
    dataIndex: "departmentHeadScore",
    key: "departmentHeadScore",
     align:"center"
  },
  {
    title: "填报状态",
    dataIndex: "beforeSumStatus",
    key: "beforeSumStatus",
    slots: { customRender: "beforeSumStatus" },
     align:"center"
  },
  {
    title: "当前评级",
    dataIndex: "assessmentGrade",
    key: "assessmentGrade",
    align: "center",
  },
  {
    title: "操作",
    dataIndex: "action",
    key: "action",
    align: "center",
    slots: { customRender: "action" },
  },
];

const getData = () => {
  GetAdutiView({
    empId: userStore.empid,
    status: 1,
  }).then((response: any) => {
    console.log(response);
    dataSource.value = response.data;
  });
};
getData();
const drawerRecord = ref(null);
const drawerVisible = ref<boolean>(false);

const confirm = (record: any) => {
  PostoneClickReview({ summaryId: record.id }).then((response: any) => {
    if (response.code == 200) {
      message.success(response.msg);
      getData();
      drawerVisible.value = false;
    } else {
      message.error(response.msg);
    }
  });
};
const handleShowDrawer = (record: any) => {
  drawerRecord.value = record;
  drawerVisible.value = true;
  detailsGetData();
};
const detailsGetData = () => {
  GetEmployeeViewDetails({
    summaryId: drawerRecord.value.id,
  }).then((response: any) => {
    drawerDataSource.value = response.data;
  });
};
// 计算属性，计算最高得分
const calculationMaxScore = computed(() => {
  return Object.values(personalScoreList.value).reduce((total, item) => {
    const childrenMaxScoreSum = item.children.reduce(
      (acc, child) => acc + child.maxScore,
      0
    );
    return total + childrenMaxScoreSum;
  }, 0);
});

// 计算属性，计算自评分
const calculationSelfRating = computed(() => {
  return Object.values(personalScoreList.value).reduce((total, item) => {
    const childrenMaxScoreSum = item.children.reduce(
      (acc, child) => acc + child.selfRating,
      0
    );
    return total + childrenMaxScoreSum;
  }, 0);
});
// 计算属性，部门评分
const calculationDepartmentRating = computed(() => {
  return Object.values(personalScoreList.value).reduce((total, item) => {
    const childrenMaxScoreSum = item.children.reduce(
      (acc, child) => acc + child.departmentRating,
      0
    );
    return total + childrenMaxScoreSum;
  }, 0);
});
// 计算属性，支部评分
const calculationBranchRating = computed(() => {
  return Object.values(personalScoreList.value).reduce((total, item) => {
    const childrenMaxScoreSum = item.children.reduce(
      (acc, child) => acc + child.branchRating,
      0
    );
    return total + childrenMaxScoreSum;
  }, 0);
});
// 计算属性，领导评分
const calculationSupervisorRating = computed(() => {
  return Object.values(personalScoreList.value).reduce((total, item) => {
    const childrenMaxScoreSum = item.children.reduce(
      (acc, child) => acc + child.supervisorRating,
      0
    );
    return total + childrenMaxScoreSum;
  }, 0);
});
// 抽屉
const visible = ref<boolean>(false);
const drawerDetailsRecord = ref(null);

const assessmentId = ref(null);
const afterVisibleChange = (bool: boolean) => {
  // console.log('visible', bool);
};
// 显示抽屉
const showDrawer = (record: any, isEdit: boolean) => {
  drawerDetailsRecord.value = record;
  assessmentId.value = record.id;
  visible.value = true;
  drawerDetailsRecord.value.isEdit = isEdit;
  if (isEdit) {
    GetQueryPersonalScoreList();
  } else {
    GetQueryRealTimeScoreList();
  }
  getWordkPlan();
};

const personalScoreList = ref([]);
const GetQueryPersonalScoreList = () => {
  GetQueryPersonalScore(drawerDetailsRecord.value).then((response: any) => {
    const groupedData = {};
    // 把考核内容list 改为树形结构
    response.forEach((item) => {
      if (!groupedData[item.contentType]) {
        groupedData[item.contentType] = {
          contentType: item.contentType,
          contentName: item.contentName,
          children: [],
        };
      }
      groupedData[item.contentType].children.push(item);
    });
    personalScoreList.value = groupedData || [];
  });
};

const GetQueryRealTimeScoreList = () => {
  GetQueryRealTimeScore(drawerDetailsRecord.value).then((response: any) => {
    const groupedData = {};
    // 把考核内容list 改为树形结构
    response.forEach((item) => {
      if (!groupedData[item.contentType]) {
        groupedData[item.contentType] = {
          contentType: item.contentType,
          contentName: item.contentName,
          children: [],
        };
      }
      groupedData[item.contentType].children.push(item);
    });
    personalScoreList.value = groupedData || [];
  });
};
const workPlan = ref([]);
// 新增计划
const handleAddWorkPlan = () => {
  workPlan.value.push({
    glid: drawerDetailsRecord.value.id,
    workPlanContent: "",
    plannedCompletionDate: "",
    remarks: "",
  });
};
// 删除计划
const handleDelWorkPlan = (index: number) => {
  workPlan.value.splice(index, 1);
};
// 保存草稿

// const employee = ref({
//     id: "",
//     jobTitle: "",// 职称
//     position: "",//岗位
//     duty: "",// 职务
//     workSummary: "",// 工作总结
//     remarks: "",//备注
//     rewardPunishmentScore: "",// 奖惩分数
//     rewardPunishmentReason: "",// 奖惩理由
//     status: '',// 流程状态

// })
// 获取工作计划
const getWordkPlan = () => {
  GetQueryPersonalWorkPlan({
    assessmentId: drawerDetailsRecord.value.id,
  }).then((response) => {
    workPlan.value = response.data;
  });
};
// 保存草稿
const handleSaveDraft = () => {
  workPlan.value.forEach((item) => {
    item.plannedCompletionDate = moment(item.plannedCompletionDate).format(
      "YYYY-MM-DD"
    );
  });
  const scores = [];
  for (const key in personalScoreList.value) {
    if (personalScoreList.value.hasOwnProperty(key)) {
      const children = personalScoreList.value[key].children;
      if (children && children.length > 0) {
        scores.push(...children);
      }
    }
  }
  let params = {
    employee: drawerDetailsRecord.value,
    subStatus: 0, //状态
    workPlans: workPlan.value, //计划
    scores: scores, //成绩
  };

  PostSubmitAssessmenteMoloyee(params).then((response) => {
    if (response.code == 200) {
      message.success(response.msg);
      visible.value = false;
      getData();
      detailsGetData();
    } else {
      message.error(response.msg);
    }
  });
};
// 提交
const handleSubmit = () => {
  workPlan.value.forEach((item) => {
    item.plannedCompletionDate = moment(item.plannedCompletionDate).format(
      "YYYY-MM-DD"
    );
  });
  const scores = [];
  for (const key in personalScoreList.value) {
    if (personalScoreList.value.hasOwnProperty(key)) {
      const children = personalScoreList.value[key].children;
      if (children && children.length > 0) {
        scores.push(...children);
      }
    }
  }
  let params = {
    employee: drawerDetailsRecord.value,
    subStatus: 1, //状态
    workPlans: workPlan.value, //计划
    scores: scores, //成绩
  };

  PostSubmitAssessmenteMoloyee(params).then((response) => {
    if (response.code == 200) {
      message.success(response.msg);
      visible.value = false;
      getData();
      detailsGetData();
    } else {
      message.error(response.msg);
    }
  });
};
</script>

<template>
  <div style="display: flex; align-items: center; justify-content: flex-end">
    <ReloadOutlined class="operation-btn" @click="getData" />
  </div>
  <br />
  <a-table
    :dataSource="dataSource"
    :columns="columns"
    bordered
    :pagination="false"
    rowKey="id"
  >
    <template #index="{ index }">
      {{ index + 1 }}
    </template>

    <template #summaryType="{ record }">
      <span>
        <a-tag color="#BDB76B" v-if="record.summaryType == 0"
          >支部书记汇总</a-tag
        >
        <a-tag color="#87d068" v-if="record.summaryType == 1"
          >分管领导汇总</a-tag
        >
      </span>
    </template>
    <template #status="{ record }">
      <span>
        <a-tag color="error" v-if="record.status == 0">待发送</a-tag>
        <a-tag color="#87d068" v-if="record.status == 1">进行中</a-tag>
        <a-tag v-if="record.status == 2">审核完毕</a-tag>
      </span>
    </template>

    <template #action="{ record }">
      <span>
        <a-tag
          color="#108ee9"
          style="cursor: pointer"
          @click="handleShowDrawer(record)"
          >详情</a-tag
        >
      </span>
    </template>
  </a-table>
  <a-drawer
    :title="
      drawerRecord &&
      drawerRecord.assessmentName +
        '&nbsp;&nbsp;共&nbsp;' +
        drawerDataSource.length +
        '&nbsp;条数据'
    "
    width="1400"
    placement="right"
    v-model:visible="drawerVisible"
  >
    <a-table
      :dataSource="drawerDataSource"
      :columns="drawerColumns"
      bordered
      :pagination="false"
      rowKey="id"
    >
      <template #index="{ index }">
        {{ index + 1 }}
      </template>
      <template #beforeSumStatus="{ record }">
        <span>
          <a-tag color="error" v-if="record.beforeSumStatus == 1">未提交</a-tag>
          <a-tag color="#87d068" v-if="record.beforeSumStatus == 0"
            >已提交</a-tag
          >
        </span>
      </template>

      <template #action="{ record }">
        <span v-if="record.beforeSumStatus == 0">
          <a-tag
            color="#108ee9"
            style="cursor: pointer"
            @click="showDrawer(record, false)"
            >详情</a-tag
          >
          <a-tag
            color="#108ee9"
            style="cursor: pointer"
            v-if="drawerRecord.status != 2"
            @click="showDrawer(record, true)"
            >重新打分</a-tag
          >
        </span>
        <span v-else>/</span>
      </template>
    </a-table>
    <br>
    <br>
    <div
      :style="{
        position: 'absolute',
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e8e8e8',
        padding: '10px 16px',
        textAlign: 'right',
        left: 0,
        background: '#fff',
        borderRadius: '0 0 4px 4px',
      }"
    >
      <a-button style="margin-right: 8px" @click="() => (drawerVisible = false)"
        >关闭</a-button
      >
      <!-- <a-button
        type="primary"
        @click="handleSaveDraft"
        style="margin-right: 8px"
      
        >保存草稿</a-button
      > -->
      <a-popconfirm
        v-if="drawerRecord && drawerRecord.status != 2"
        placement="topLeft"
        title="是否一键审核?"
        ok-text="是"
        cancel-text="否"
        @confirm="confirm(drawerRecord)"
      >
        <a-button type="primary">一键审核</a-button>
      </a-popconfirm>
    </div>
  </a-drawer>
  <a-drawer
    :title="
      drawerDetailsRecord &&
      drawerDetailsRecord.empname +
        '&nbsp;&nbsp;填报月份: &nbsp;&nbsp;' +
        drawerDetailsRecord.reportingMonth
    "
    placement="right"
    v-model:visible="visible"
    width="1300"
    :after-visible-change="afterVisibleChange"
  >
    <h2 style="text-align: center; font-weight: bold">双月工作考核表</h2>
    <!-- 编辑 -->
    <div
      style="margin-bottom: 60px"
      v-if="drawerDetailsRecord && drawerDetailsRecord.isEdit"
    >
      <div style="border-top: 1px solid #f0f0f0">
        <div class="table-header">
          <div style="width: 100px">姓名</div>
          <div style="flex: 1">{{ drawerDetailsRecord.empname }}</div>
          <div style="flex: 1">部门</div>
          <div style="flex: 1">{{ drawerDetailsRecord.orgName }}</div>
          <div style="flex: 1">职称</div>
          <div style="flex: 2">
            {{ drawerDetailsRecord.jobTitle }}
          </div>
          <div style="width: 100px">岗位</div>
          <div style="flex: 2">
            {{ drawerDetailsRecord.position }}
          </div>
          <div style="width: 100px">职务</div>
          <div style="flex: 1">
            {{ drawerDetailsRecord.duty }}
          </div>
        </div>
        <div class="table-header">
          <div style="background: #fafafa; width: 100%">工作总结</div>
        </div>
        <div class="table-header">
          <div
            style="
              height: 120px;
              width: 100%;
              display: flex;
              justify-content: flex-start;
              align-items: flex-start;
            "
          >
            <span style="padding: 10px">{{
              drawerDetailsRecord.workSummary
            }}</span>
          </div>
        </div>

        <div class="table-header">
          <div style="width: 100px">备注</div>
          <div style="flex: 11; display: flex; justify-content: flex-start">
            <span style="padding: 0 10px">{{
              drawerDetailsRecord.remarks
            }}</span>
          </div>
        </div>
        <!-- <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11">
                        请上传附件
                    </div>
                </div> -->
        <div class="table-header">
          <div style="background: #fafafa; width: 100%; position: relative">
            <div style="border: none">工作计划</div>
          </div>
        </div>
        <div class="table-header">
          <div style="width: 100px">序号</div>
          <div style="flex: 4">工作计划</div>
          <div style="width: 140px">拟定完成工作时间</div>
          <div style="flex: 4">备注</div>
        </div>
        <div
          class="table-header"
          v-for="(item, index) in workPlan"
          :key="index"
        >
          <div style="width: 100px">{{ index + 1 }}</div>
          <div style="flex: 4">
            <span>{{ item.workPlanContent }}</span>
          </div>
          <div style="width: 140px; padding: 0 10px">
            <span>{{ item.plannedCompletionDate }}</span>
          </div>
          <div style="flex: 4">
            <span>{{ item.remarks }}</span>
          </div>
        </div>
        <div class="table-header">
          <div style="background: #fafafa; width: 100%">工作考核自评</div>
        </div>
        <div class="table-header">
          <div style="width: 100px">岗位职责</div>
          <div style="flex: 11">
            <a-input value="5"></a-input>
          </div>
        </div>
        <div class="table-header">
          <div rowspan="2" style="width: 100px">考核项</div>
          <div style="flex: 6; padding: 0 10px">考核内容</div>
          <div style="flex: 1">最高得分</div>
          <div
            style="flex: 1"
            v-if="drawerDetailsRecord && drawerDetailsRecord.personnelType == 0"
          >
            自评分
          </div>
          <div
            style="flex: 1"
            v-if="
              drawerDetailsRecord.personnelType == 0 ||
              drawerDetailsRecord.personnelType == 1
            "
          >
            部门评分
          </div>
          <div style="flex: 1">支部评分</div>
          <div style="flex: 1">领导评分</div>
        </div>
        <div
          class="table-header"
          v-for="(item, index) in personalScoreList"
          :key="index"
          style="display: flex"
        >
          <div style="width: 100px">{{ item.contentName }}</div>
          <div
            style="
              flex: 1;
              display: flex;
              flex-direction: column;
              border-right: none;
              border-bottom: none;
            "
          >
            <div
              v-for="children in item.children"
              :key="children.id"
              style="
                width: 1134px;
                display: flex;
                border-bottom: 1px solid #f0f0f0;
              "
              class="table-chidren"
            >
              <div
                style="flex: 6; justify-content: flex-start; padding: 0 10px"
              >
                <!-- {{ children &&children.content }} -->
                <span v-html="children.content"></span>
              </div>
              <div style="flex: 1">{{ children.maxScore }}</div>
              <div
                style="flex: 1"
                class="clear-border"
                v-if="
                  drawerDetailsRecord && drawerDetailsRecord.personnelType == 0
                "
              >
                <a-input-number
                  style="height: 30px"
                  min="0"
                  :max="children.maxScore"
                  v-model:value="children.selfRating"
                  v-if="
                    drawerDetailsRecord.status == 1 ||
                    drawerDetailsRecord.status == -2 ||
                    drawerDetailsRecord.status == -3
                  "
                />
                <div v-else style="border: none">{{ children.selfRating }}</div>
              </div>
              <div
                style="flex: 1"
                class="clear-border"
                v-if="
                  drawerDetailsRecord.personnelType == 0 ||
                  drawerDetailsRecord.personnelType == 1
                "
              >
                <a-input-number
                  style="height: 30px"
                  min="0"
                  :max="children.maxScore"
                  v-model:value="children.departmentRating"
                  v-if="drawerDetailsRecord.status == 2"
                />
                <div v-else style="border: none">
                  {{ children.departmentRating }}
                </div>
              </div>
              <div style="flex: 1" class="clear-border">
                <a-input-number
                  style="height: 30px"
                  min="0"
                  :max="children.maxScore"
                  v-model:value="children.branchRating"
                  v-if="drawerDetailsRecord.status == 101"
                />
                <div v-else style="border: none">
                  {{ children.branchRating }}
                </div>
              </div>
              <div
                style="flex: 1; border-right: 1px solid #f0f0f0"
                class="clear-border"
              >
                <a-input-number
                  style="height: 30px"
                  min="0"
                  :max="children.maxScore"
                  v-model:value="children.supervisorRating"
                  v-if="
                    drawerDetailsRecord.status == 3 ||
                    drawerDetailsRecord.status == 102
                  "
                />
                <div v-else style="border: none">
                  {{ children.supervisorRating }}
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="table-header">
          <div style="width: 100px">合并</div>
          <div style="flex: 6; padding: 0 10px"></div>
          <div style="flex: 1">总分：{{ calculationMaxScore }}</div>
          <div
            style="flex: 1"
            v-if="drawerDetailsRecord && drawerDetailsRecord.personnelType == 0"
          >
            总分：{{ calculationSelfRating }}
          </div>
          <div
            style="flex: 1"
            v-if="
              drawerDetailsRecord.personnelType == 0 ||
              drawerDetailsRecord.personnelType == 1
            "
          >
            总分：{{ calculationDepartmentRating }}
          </div>
          <div style="flex: 1">总分：{{ calculationBranchRating }}</div>
          <div style="flex: 1">总分：{{ calculationSupervisorRating }}</div>
        </div>
        <div class="table-header">
          <div style="width: 100px">奖惩分数</div>
          <div style="flex: 1">
            <a-input
              type="text"
              v-model:value="drawerDetailsRecord.rewardPunishmentScore"
            />
          </div>
          <div style="width: 100px">理由</div>
          <div style="flex: 10">
            <a-input
              type="text"
              placeholder="请输入理由"
              v-model:value="drawerDetailsRecord.rewardPunishmentReason"
            />
          </div>
        </div>
        <div class="table-header">
          <div style="width: 100px">评定等级</div>
          <div style="flex: 11;color: #f00f00;display: flex;justify-content: flex-start;padding-left: 20px;">
                        <span v-if="drawerDetailsRecord.status == 1 || drawerDetailsRecord.status == -2 || drawerDetailsRecord.status == -3">
                            <span v-if="drawerDetailsRecord.personnelType == 0">
                                <span v-if="calculationSelfRating >= 95">A1</span>
                                <span v-if="calculationSelfRating >= 91 && calculationSelfRating <= 94">A2</span>
                                <span v-if="calculationSelfRating >= 86 && calculationSelfRating <= 90">B1</span>
                                <span v-if="calculationSelfRating >= 81 && calculationSelfRating <= 85">B2</span>
                                <span v-if="calculationSelfRating >= 76 && calculationSelfRating <= 81">B3</span>
                                <span v-if="calculationSelfRating >= 71 && calculationSelfRating <= 75">C1</span>
                                <span v-if="calculationSelfRating >= 60 && calculationSelfRating <= 70">C2</span>
                                <span v-if="calculationSelfRating <= 59"></span>
                            </span>
                            <span v-else>
                               暂无
                            </span>
                        </span>
                        <span v-if="drawerDetailsRecord.status == 2">
                            <span v-if="drawerDetailsRecord.personnelType == 0">
                                <span v-if="calculationDepartmentRating >= 95">A1</span>
                                <span v-if="calculationDepartmentRating >= 91 && calculationDepartmentRating <= 94">A2</span>
                                <span v-if="calculationDepartmentRating >= 86 && calculationDepartmentRating <= 90">B1</span>
                                <span v-if="calculationDepartmentRating >= 81 && calculationDepartmentRating <= 85">B2</span>
                                <span v-if="calculationDepartmentRating >= 76 && calculationDepartmentRating <= 81">B3</span>
                                <span v-if="calculationDepartmentRating >= 71 && calculationDepartmentRating <= 75">C1</span>
                                <span v-if="calculationDepartmentRating >= 60 && calculationDepartmentRating <= 70">C2</span>
                                <span v-if="calculationDepartmentRating <= 59"></span>
                            </span>
                            <span v-if="drawerDetailsRecord.personnelType == 1 || drawerDetailsRecord.personnelType == 2">
                                <span v-if="calculationDepartmentRating >= 91">A</span>
                                <span v-if="calculationDepartmentRating >= 76 && calculationDepartmentRating <= 90">B</span>
                                <span v-if="calculationDepartmentRating >= 60 && calculationDepartmentRating <= 75">C</span>
                                <span v-if="calculationDepartmentRating <= 59">D</span>
                            </span>
                        </span>
                        <span v-if="drawerDetailsRecord.status == 3">
                            <span v-if="drawerDetailsRecord.personnelType == 0">
                                暂无
                            </span>
                            <span v-if="drawerDetailsRecord.personnelType == 1 || drawerDetailsRecord.personnelType == 2">
                                <span v-if="calculationSupervisorRating >= 91">A</span>
                                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 90">B</span>
                                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 75">C</span>
                                <span v-if="calculationSupervisorRating <= 59">D</span>
                            </span>
                        </span>
                        <span v-if="drawerDetailsRecord.status == 101">
                            <!-- 普通员工 -->
                            <span v-if="drawerDetailsRecord.personnelType == 0">  
                                <span v-if="calculationBranchRating >= 95">A1</span>
                                <span v-if="calculationBranchRating >= 91 && calculationBranchRating <= 94">A2</span>
                                <span v-if="calculationBranchRating >= 86 && calculationBranchRating <= 90">B1</span>
                                <span v-if="calculationBranchRating >= 81 && calculationBranchRating <= 85">B2</span>
                                <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 81">B3</span>
                                <span v-if="calculationBranchRating >= 71 && calculationBranchRating <= 75">C1</span>
                                <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 70">C2</span>
                                <span v-if="calculationBranchRating <= 59"></span>
                            </span>
                            <span v-if="drawerDetailsRecord.personnelType == 1 || drawerDetailsRecord.personnelType == 2">
                                <span v-if="calculationBranchRating >= 91">A</span>
                                <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 90">B</span>
                                <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 75">C</span>
                                <span v-if="calculationBranchRating <= 59">D</span>
                            </span>
                        </span>
                        <span v-if="drawerDetailsRecord.status == 102">
                            <!-- 普通员工 -->
                            <span v-if="drawerDetailsRecord.personnelType == 0">  
                                <span v-if="calculationSupervisorRating >= 95">A1</span>
                                <span v-if="calculationSupervisorRating >= 91 && calculationSupervisorRating <= 94">A2</span>
                                <span v-if="calculationSupervisorRating >= 86 && calculationSupervisorRating <= 90">B1</span>
                                <span v-if="calculationSupervisorRating >= 81 && calculationSupervisorRating <= 85">B2</span>
                                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 81">B3</span>
                                <span v-if="calculationSupervisorRating >= 71 && calculationSupervisorRating <= 75">C1</span>
                                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 70">C2</span>
                                <span v-if="calculationSupervisorRating <= 59"></span>
                            </span>
                            <span v-if="drawerDetailsRecord.personnelType == 1 || drawerDetailsRecord.personnelType == 2">
                                <span v-if="calculationSupervisorRating >= 91">A</span>
                                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 90">B</span>
                                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 75">C</span>
                                <span v-if="calculationSupervisorRating <= 59">D</span>
                            </span>
                        </span>
                    </div>
          <!-- <div
            style="
              flex: 11;
              color: #f00f00;
              display: flex;
              justify-content: flex-start;
              padding-left: 20px;
            "
          >
          <span v-if="drawerDetailsRecord.personnelType == 0">
             <span v-if="drawerDetailsRecord.status==102">
              <span v-if="calculationSupervisorRating >= 91">A</span>
                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 90">B</span>
                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 75">C</span>
                <span v-if="calculationSupervisorRating <= 59">D</span>
             </span>
             <span v-else>
              <span v-if="calculationBranchRating >= 95">A1</span>
              <span v-if="calculationBranchRating >= 91 && calculationBranchRating <= 94">A2</span>
              <span v-if="calculationBranchRating >= 86 && calculationBranchRating <= 90">B1</span>
              <span v-if="calculationBranchRating >= 81 && calculationBranchRating <= 85">B2</span>
              <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 81">B3</span>
              <span v-if="calculationBranchRating >= 71 && calculationBranchRating <= 75">C1</span >
              <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 70">C2</span>
              <span v-if="calculationBranchRating <= 59">D</span>
             </span>
            </span>
            <span v-if="drawerDetailsRecord.personnelType == 1">
              <span v-if="drawerDetailsRecord.status == 101">
                <span v-if="calculationBranchRating >= 91">A</span>
                <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 90">B</span>
                <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 75">C</span>
                <span v-if="calculationBranchRating <= 59">D</span>
              </span>
              <span v-else>
                <span v-if="calculationSelfRating >= 91">A</span>
                <span v-if="calculationSelfRating >= 76 && calculationSelfRating <= 90">B</span>
                <span v-if="calculationSelfRating >= 60 && calculationSelfRating <= 75">C</span>
                <span v-if="calculationSelfRating <= 59">D</span>
              </span>
            </span>
            <span v-if="drawerDetailsRecord.personnelType == 2">
             <span v-if="drawerDetailsRecord.status == 102">
                <span v-if="calculationSupervisorRating >= 91">A</span>
                <span v-if="calculationSupervisorRating >= 76 && calculationSupervisorRating <= 90">B</span>
                <span v-if="calculationSupervisorRating >= 60 && calculationSupervisorRating <= 75">C</span>
                <span v-if="calculationSupervisorRating <= 59">D</span>
             </span>
             <span v-if="drawerDetailsRecord.status == 101">
                <span v-if="calculationBranchRating >= 91">A</span>
                <span v-if="calculationBranchRating >= 76 && calculationBranchRating <= 90">B</span>
                <span v-if="calculationBranchRating >= 60 && calculationBranchRating <= 75">C</span>
                <span v-if="calculationBranchRating <= 59">D</span>
             </span>
             
            </span>
          </div> -->
        </div>
      </div>
    </div>

    <!-- 查看 -->
    <div
      style="margin-bottom: 60px"
      v-if="drawerDetailsRecord && !drawerDetailsRecord.isEdit"
    >
      <div style="border-top: 1px solid #f0f0f0">
        <div class="table-header">
          <div style="width: 100px">姓名</div>
          <div style="flex: 1">{{ drawerDetailsRecord.empname }}</div>
          <div style="flex: 1">部门</div>
          <div style="flex: 1">{{ drawerRecord.orgName }}</div>
          <div style="flex: 1">职称</div>
          <div style="flex: 2">
            <span>{{ drawerDetailsRecord.jobTitle }}</span>
          </div>
          <div style="width: 100px">岗位</div>
          <div style="flex: 2">
            <span>{{ drawerDetailsRecord.position }}</span>
          </div>
          <div style="width: 100px">职务</div>
          <div style="flex: 1">
            <span>{{ drawerDetailsRecord.duty }}</span>
          </div>
        </div>
        <div class="table-header">
          <div style="background: #fafafa; width: 100%">工作总结</div>
        </div>
        <div class="table-header">
          <div
            style="
              height: 120px;
              width: 100%;
              display: flex;
              justify-content: flex-start;
              align-items: flex-start;
            "
          >
            <span style="padding: 10px">{{
              drawerDetailsRecord.workSummary
            }}</span>
          </div>
        </div>

        <div class="table-header">
          <div style="width: 100px">备注</div>
          <div style="flex: 11; display: flex; justify-content: flex-start">
            <span style="padding: 0 10px">{{
              drawerDetailsRecord.remarks
            }}</span>
          </div>
        </div>
        <!-- <div class="table-header">
                    <div style="width: 100px">
                        附件
                    </div>
                    <div style="flex:11">
                        请上传附件
                    </div>
                </div> -->
        <div class="table-header">
          <div style="background: #fafafa; width: 100%; position: relative">
            <div style="border: none">工作计划</div>
            <a-button
              style="position: absolute; right: 20px"
              size="small"
              type="primary"
              v-if="drawerDetailsRecord.isEdit"
              @click="handleAddWorkPlan"
              >新增</a-button
            >
          </div>
        </div>
        <div class="table-header">
          <div style="width: 100px">序号</div>
          <div style="flex: 4">工作计划</div>
          <div style="width: 140px">拟定完成工作时间</div>
          <div style="flex: 4">备注</div>
        </div>
        <div
          class="table-header"
          v-for="(item, index) in workPlan"
          :key="index"
        >
          <div style="width: 100px">{{ index + 1 }}</div>
          <div style="flex: 4">
            <span>{{ item.workPlanContent }}</span>
          </div>
          <div style="width: 140px; padding: 0 10px">
            <span>{{ item.plannedCompletionDate }}</span>
          </div>
          <div style="flex: 4">
            <span>{{ item.remarks }}</span>
          </div>
        </div>
        <div class="table-header" v-if="workPlan.length == 0">
          <div style="width: 100%; color: #f00f00">请添加工作计划</div>
        </div>
        <div class="table-header">
          <div style="background: #fafafa; width: 100%">工作考核自评</div>
        </div>
        <div class="table-header">
          <div style="width: 100px">岗位职责</div>
          <div style="flex: 11">
            <a-input value="5"></a-input>
          </div>
        </div>
        <div class="table-header">
          <div rowspan="2" style="width: 100px">考核项</div>
          <div style="flex: 6; padding: 0 10px">考核内容</div>
          <div style="flex: 1">最高得分</div>
          <div style="flex: 1">自评分</div>
          <div style="flex: 1">部门评分</div>
          <div style="flex: 1">支部评分</div>
          <div style="flex: 1">领导评分</div>
        </div>
        <div
          class="table-header"
          v-for="(item, index) in personalScoreList"
          :key="index"
          style="display: flex"
        >
          <div style="width: 100px">{{ item.contentName }}</div>
          <div
            style="
              flex: 1;
              display: flex;
              flex-direction: column;
              border-right: none;
              border-bottom: none;
            "
          >
            <div
              v-for="children in item.children"
              :key="children.id"
              style="
                width: 1134px;
                display: flex;
                border-bottom: 1px solid #f0f0f0;
              "
              class="table-chidren"
            >
              <div
                style="flex: 6; justify-content: flex-start; padding: 0 10px"
              >
                <!-- {{ children &&children.content }} -->
                <span v-html="children.content"></span>
              </div>
              <div style="flex: 1">{{ children.maxScore }}</div>
              <div style="flex: 1" class="clear-border">
                <div style="border: none">{{ children.selfRating }}</div>
              </div>
              <div style="flex: 1" class="clear-border">
                <div style="border: none">{{ children.departmentRating }}</div>
              </div>
              <div style="flex: 1" class="clear-border">
                <div style="border: none">{{ children.branchRating }}</div>
              </div>
              <div
                style="flex: 1; border-right: 1px solid #f0f0f0"
                class="clear-border"
              >
                <div style="border: none">{{ children.supervisorRating }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="table-header">
          <div style="width: 100px">合并</div>
          <div style="flex: 6; padding: 0 10px"></div>
          <div style="flex: 1">总分：{{ calculationMaxScore }}</div>
          <div style="flex: 1">总分：{{ calculationSelfRating }}</div>
          <div style="flex: 1">总分：{{ calculationDepartmentRating }}</div>
          <div style="flex: 1">总分：{{ calculationBranchRating }}</div>
          <div style="flex: 1">总分：{{ calculationSupervisorRating }}</div>
        </div>
        <div class="table-header">
          <div style="width: 100px">奖惩分数</div>
          <div style="flex: 1">
            {{ drawerDetailsRecord.rewardPunishmentScore }}
          </div>
          <div style="width: 100px">理由</div>
          <div style="flex: 10; justify-content: flex-start; padding: 0 10px">
            {{ drawerDetailsRecord.rewardPunishmentReason }}
          </div>
        </div>
        <!-- <div class="table-header">
          <div style="width: 100px">评定等级</div>
          <div
            style="
              flex: 11;
              color: #f00f00;
              display: flex;
              justify-content: flex-start;
              padding-left: 20px;
            "
          >
            <span v-if="drawerDetailsRecord.personnelType != 1">
              <span v-if="calculationSelfRating >= 91">A</span>
              <span
                v-if="
                  calculationSelfRating >= 76 && calculationSelfRating <= 90
                "
                >B</span
              >
              <span
                v-if="
                  calculationSelfRating >= 60 && calculationSelfRating <= 75
                "
                >C</span
              >
              <span v-if="calculationSelfRating <= 59">D</span>
            </span>
            <span v-else>
              <span v-if="calculationSelfRating >= 95">A1</span>
              <span
                v-if="
                  calculationSelfRating >= 91 && calculationSelfRating <= 94
                "
                >A2</span
              >
              <span
                v-if="
                  calculationSelfRating >= 86 && calculationSelfRating <= 90
                "
                >B1</span
              >
              <span
                v-if="
                  calculationSelfRating >= 81 && calculationSelfRating <= 85
                "
                >B2</span
              >
              <span
                v-if="
                  calculationSelfRating >= 76 && calculationSelfRating <= 81
                "
                >B3</span
              >
              <span
                v-if="
                  calculationSelfRating >= 71 && calculationSelfRating <= 75
                "
                >C1</span
              >
              <span
                v-if="
                  calculationSelfRating >= 60 && calculationSelfRating <= 70
                "
                >C2</span
              >
              <span v-if="calculationSelfRating <= 59"></span>
            </span>
          </div>
        </div> -->
      </div>
    </div>
    <div
      :style="{
        position: 'absolute',
        bottom: 0,
        width: '100%',
        borderTop: '1px solid #e8e8e8',
        padding: '10px 16px',
        textAlign: 'right',
        left: 0,
        background: '#fff',
        borderRadius: '0 0 4px 4px',
      }"
    >
      <a-button style="margin-right: 8px" @click="() => (visible = false)"
        >关闭</a-button
      >
      <!-- <a-button
        type="primary"
        @click="handleSaveDraft"
        style="margin-right: 8px"
      
        >保存草稿</a-button
      > -->
      <a-button type="primary" @click="handleSubmit"  v-if="drawerDetailsRecord && drawerDetailsRecord.isEdit">提交</a-button>
    </div>
  </a-drawer>
</template>

<style scoped>
.table-header {
  display: flex;
  width: 1235px;
  /* align-items: center; */
  /* border-top: 1px solid #f0f0f0; */
  border-left: 1px solid #f0f0f0;
}

.table-header > div {
  border-right: 1px solid #f0f0f0;
  border-bottom: 1px solid #f0f0f0;
  /* flex: 1; */
  /* height: 50px; */
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ant-input {
  border: none !important;
}

.ant-input:focus {
  border: none !important;
  box-shadow: none !important;
}

.clear-border {
  align-items: normal;
}

.clear-border div {
  border: 1px solid #d9d9d9;
  min-height: 30px;
}

.table-chidren > div {
  border-bottom: none;
  line-height: 2;
  border-right: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 0;
}

.operation-btn {
  border: 1px solid #f2f3f5;
  width: 35px;
  height: 35px;
  display: block;
  border-radius: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  margin-left: 10px;
  font-weight: 700;
}

.operation-btn:hover {
  background: #f2f3f5;
  color: #1677ff;
}
</style>
